package com.eatme.web.security.authentication.constant;

import java.util.Objects;
import java.util.stream.Stream;

public enum IdentityType {

    PASSWORD("密码",1),
    PHONE("手机号",2),
    EMAIL("邮箱",3),
    APPLET("微信小程序",4);

    /** 登录类型描述 */
    private String description;

    /** 登录类型编码 */
    private Integer code;

    IdentityType(String description, Integer code) {
        this.description = description;
        this.code = code;
    }

    /**
     * 根据code 获取 CouponStatus
     * @param code
     * @return
     */
    public static IdentityType of(Integer code) {
        Objects.requireNonNull(code);
        return Stream.of(values())
                .filter(bean -> bean.code.equals(code))
                .findAny().orElseThrow(
                        () -> new IllegalArgumentException(code + "not exists"));
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

}
